package OOday03;

public class HomeWork {
    public static void main(String[] args) {
//        Apple[]apples=new Apple[2];
//        apples[0]=new Apple("耿梦蕾","苹果",6000);
//        apples[1]=new Apple("小胖","苹果",5000);
//        for(int i=0;i<apples.length;i++){
 //           apples[i].buy();
  //          apples[i].openComputer();
 //           apples[i].function();
 //           apples[i].working();
 //           apples[i].game();
 //           apples[i].closeComputer();
 //   }
      Computer []computers=new Computer[3];
      computers[0]=new Apple("小胖","苹果",2000);
      computers[1]=new XiaoMi("胡","小米",20000);
      computers[2]=new HuaWei("方","华为",1211);
      for (int i=0;i< computers.length;i++){
         computers[i].buy();
         computers[i].openComputer();
         computers[i].function();
         computers[i].closeComputer();
         if (computers[i] instanceof Apple){
             Apple apple=(Apple) computers[i];
             apple.game();
             apple.working();
         }
         if (computers [i]instanceof XiaoMi){
             XiaoMi xiaoMi=(XiaoMi)computers[i];
             xiaoMi.game();
         }
         if (computers[i]instanceof HuaWei){
             HuaWei huaWei=(HuaWei) computers[i];
             huaWei.working();
         }
      }


 /*     Master masters=new Master();
      Apple apple=new Apple("胖","华为",2000);
      masters.function(apple);

 */
    }
}
 abstract class Computer{
    String name;
    String computerName;
    int price;
    Computer(String name, String computerName,int price){
        this.name=name;
        this.computerName=computerName;
        this.price=price;
    }
    abstract void function();
    void openComputer(){
        System.out.println(name+"打开了"+computerName+"电脑...");
    }
    void closeComputer(){
        System.out.println(name+"关掉了"+computerName+"电脑...");
    }
    void buy(){
        System.out.println(name+"买了一台"+computerName+"电脑花了"+price+"元");
    }
}
interface Inter5{
    void working();
}
interface Inter6{
    void game();
}
 class HuaWei extends Computer implements Inter5{
    HuaWei(String name,String computer,int price){
        super(name,computer,price);
    }
    void function(){
        System.out.println(computerName+"可以召唤小艺助手");
    }
    public void working(){
        System.out.println(computerName+"可以办公");
    }
}
  class XiaoMi extends Computer implements Inter6{
    XiaoMi(String name,String computer,int price){
        super(name,computer,price);
    }
    void function(){
        System.out.println(computerName+"可以召唤小爱同学");
    }
    public void game(){
        System.out.println(computerName+"可以打游戏");
    }
}
 class Apple extends Computer implements Inter5,Inter6{
    Apple(String name,String computer,int price){
        super(name,computer,price);
    }
    void function(){
        System.out.println(computerName+"可以召唤sir助手");
    }
    public void working(){
        System.out.println(computerName+"可以办公");
    }
    public void game(){
        System.out.println(computerName+"可以打游戏");
    }
}
class Master{
    void function(Computer computers){
       computers.function();
    }
}

